// // 路由配置信息
// // 引入路由组件
// import Home from '@/pages/Home/index.vue'
// import Search from '@/pages/Search/index.vue'
// import Login from '@/pages/Login/index.vue'
// import Register from '@/pages/Register/index.vue'
// import Detail from '@/pages/Detail/index.vue'
// import AddCartSuccess from '@/pages/AddCartSuccess/index.vue'
// import ShopCart from '@/pages/ShopCart/index.vue'
// import Trade from '@/pages/Trade/index.vue'
// import Pay from '@/pages/Pay/index.vue'
// import PaySuccess from '@/pages/PaySuccess/index.vue'
// import Center from '@/pages/Center/index.vue'
// // 引入二级路由组件
// import MyOrder from '@/pages/Center/myOrder/index.vue'
// import GroupOrder from '@/pages/Center/groupOrder/index.vue'


/**
 * 当打包构建应用时，JavaScript 包会变得非常大，影响页面加载。
 * 如果我们能把不同路由对应的组件分割成不同的代码块，然后当路由被访问的时候才加载对应组件，这样就会更加高效。
 */
// 配置路由信息
export default [
  {
    path: '/center',
    name: 'center',
    component: ()=>import('@/pages/Center/index.vue'),
    meta: { show: true },
    // 二级路由组件
    children: [
      {
        path: 'myorder',
        component: ()=>import('@/pages/Center/myOrder/index.vue'),
      },
      {
        path: 'grouporder',
        component: ()=>import('@/pages/Center/groupOrder/index.vue')
      },
      {
        path: '/center',
        redirect: '/center/myorder'
      }
    ]
  },
  {
    path: '/paysuccess',
    name: 'paysuccess',
    component: ()=>import('@/pages/PaySuccess/index.vue'),
    meta: { show: true }
  },
  {
    path: '/pay',
    name: 'pay',
    component: ()=>import('@/pages/Pay/index.vue'),
    meta: { show: true },
    beforeEnter: (to, from, next) => {
      if(from.path == '/trade'){
        next()
      } else{
        next(false)
      }
    }
  },
  {
    path: '/trade',
    name: 'trade',
    component: ()=>import('@/pages/Trade/index.vue'),
    meta: { show: true },
    // 路由独享守卫
    beforeEnter: (to, from, next) => {
      // 去交哟页面，必须是从购物车而来
      if(from.path == '/shopcart') {
        next()
      } else {
        // 其他的路由组件而来，停留在当前
        next(false)
      }
    }
  },
  {
    path: '/shopcart',
    name: 'shopcart',
    component: ()=>import('@/pages/ShopCart/index.vue'),
    meta: { show: true }
  },
  {
    path: '/addcartsuccess',
    name: 'addcartsuccess',
    component: ()=>import('@/pages/AddCartSuccess/index.vue'),
    meta: { show: true }
  },
  {
    path: '/detail/:skuid',
    component: ()=>import('@/pages/Detail/index.vue'),
    meta: { show: true },
  },
  {
    path: '/home',
    component: ()=>import('@/pages/Home/index.vue'),
    // 路由元信息key不能瞎写：只能叫做meta
    meta: { show: true },
  },
  {
    path: '/search/:keyword?',
    component: ()=>import('@/pages/Search/index.vue'),
    meta: { show: true },
    name: 'search',
    // 路由组件能不能传递props数据?
    // 布尔值写法: params
    // props: true,
    // 对象写法：额外的给路由传递一些props
    // props: {a:1, b:2},
    // 函数写法：可以params参数，query线束，通过props传递给路由组件
    props: ($route) => ({ keyword: $route.params.keyword, k: $route.query.k }),
  },
  {
    path: '/login',
    component: ()=>import('@/pages/Login/index.vue'),
    meta: { show: false },
  },
  {
    path: '/register',
    component: ()=>import('@/pages/Register/index.vue'),
    meta: { show: false },
  },
  // 重定向，在项目跑起来的时候，访问/，立马让他定向到首页
  {
    path: '/',
    redirect: '/home',
  },
]